package com.nbsaas.boot.user.rest.convert;

import com.nbsaas.boot.rest.api.Converter;
import com.nbsaas.boot.user.api.domain.simple.StructureSimple;
import com.nbsaas.boot.user.data.entity.Structure;
import lombok.Data;

/**
 * 组织架构-列表对象转换器
 */

@Data
public class StructureSimpleConvert implements Converter<StructureSimple, Structure> {


    private int fetch;


    @Override
    public StructureSimple convert(Structure source) {
        StructureSimple result = new StructureSimple();


        try {
            if (source.getParent() != null) {
                result.setParent(source.getParent().getId());
            }
        } catch (Exception ignored) {
        }


        try {
            if (source.getParent() != null) {
                result.setParentName(source.getParent().getName());
            }
        } catch (Exception ignored) {
        }

        result.setCode(source.getCode());
        result.setDepth(source.getDepth());
        result.setName(source.getName());
        result.setIds(source.getIds());
        result.setSortNum(source.getSortNum());
        result.setId(source.getId());
        result.setLft(source.getLft());
        result.setAddDate(source.getAddDate());
        result.setRgt(source.getRgt());
        result.setLastDate(source.getLastDate());

        result.setLabel(source.getName());
        result.setValue("" + source.getId());
        if (result.getCode() == null) {
            result.setCode("");
        }

        return result;
    }

}